package com.adingxiong.ribbon.controller;

import com.adingxiong.pojo.Item;
import com.adingxiong.pojo.User;
import com.adingxiong.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @ClassName RibbonController
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/7/30 17:01
 **/
@RestController
@Slf4j
public class RibbonController {

    @Autowired
    private RestTemplate template;


    @GetMapping("/item-service/getItems")
    public JsonResult<List<Item>> getItems(String orderId){
        return template.getForObject("http://item-service/getItems",JsonResult.class,orderId);
    }

    @PostMapping("/item-service/decreaseNumber")
    public JsonResult decreaseNumber(List<Item> list){
        return template.postForObject("http://item-service/decreaseNumber",list, JsonResult.class);
    }


    @GetMapping("/user-service/getUser")
    public JsonResult<User> getUser(Integer id){
        return template.getForObject("http://user-service/getUser",JsonResult.class,id);
    }

    @GetMapping("/user-service/addSocres")
    public JsonResult addSocres(Integer id ,Integer socres){
        return template.getForObject("http://user-service/addSocres",JsonResult.class ,id,socres);
    }
}
